package cn.seocoo.platform.base.service.impl;

import java.security.PrivateKey;
import java.util.Iterator;
import java.util.List;

import cn.seocoo.platform.base.dto.BaseCommonDto;
import cn.seocoo.platform.base.dto.BaseCommonParentsDto;
import cn.seocoo.platform.base.dto.BaseVehicleTypeDto;
import cn.seocoo.platform.base.mapper.BaseCategoryMapper;
import cn.seocoo.platform.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.seocoo.platform.base.mapper.BaseVehicleTypeMapper;
import cn.seocoo.platform.base.domain.BaseVehicleType;
import cn.seocoo.platform.base.service.IBaseVehicleTypeService;
import cn.seocoo.platform.common.core.text.Convert;

/**
 * 车型 服务层实现
 * 
 * @author wujian
 * @date 2019-12-18
 */
@Service
public class BaseVehicleTypeServiceImpl implements IBaseVehicleTypeService 
{
	@Autowired
	private BaseVehicleTypeMapper baseVehicleTypeMapper;

	@Autowired
	private BaseCategoryMapper baseCategoryMapper;

	/**
     * 查询车型信息
     * 
     * @param id 车型ID
     * @return 车型信息
     */
    @Override
	public BaseVehicleType selectBaseVehicleTypeById(Integer id)
	{
	    return baseVehicleTypeMapper.selectBaseVehicleTypeById(id);
	}
	
	/**
     * 查询车型列表
     * 
     * @param baseVehicleType 车型信息
     * @return 车型集合
     */
	@Override
	public List<BaseVehicleType> selectBaseVehicleTypeList(BaseVehicleType baseVehicleType)
	{
	    return baseVehicleTypeMapper.selectBaseVehicleTypeList(baseVehicleType);
	}
	
    /**
     * 新增车型
     * 
     * @param baseVehicleType 车型信息
     * @return 结果
     */
	@Override
	public int insertBaseVehicleType(BaseVehicleType baseVehicleType)
	{
	    return baseVehicleTypeMapper.insertBaseVehicleType(baseVehicleType);
	}
	
	/**
     * 修改车型
     * 
     * @param baseVehicleType 车型信息
     * @return 结果
     */
	@Override
	public int updateBaseVehicleType(BaseVehicleType baseVehicleType)
	{
	    return baseVehicleTypeMapper.updateBaseVehicleType(baseVehicleType);
	}

	/**
     * 删除车型对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteBaseVehicleTypeByIds(String ids)
	{
		return baseVehicleTypeMapper.deleteBaseVehicleTypeByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<BaseVehicleTypeDto> getVehicleTypeList() {
		return baseVehicleTypeMapper.getVehicleTypeList();
	}

	/**
	 * @Author WuJian
	 * @Description //查询车型和车辆类别集合
	 * @Date 11:02 2020/1/6
	 * @Param []
	 * @return java.util.List<cn.seocoo.platform.base.dto.BaseCommonParentsDto>
	 **/
	@Override
	public List<BaseCommonParentsDto> selectBaseVehicleTypeForDto() {
		List<BaseCommonParentsDto> vehicleTypeList = baseVehicleTypeMapper.selectBaseVehicleTypeForDto();
		if (StringUtils.isNotEmpty(vehicleTypeList)) {
			Iterator<BaseCommonParentsDto> it = vehicleTypeList.iterator();
			while (it.hasNext()) {
				BaseCommonParentsDto dto = it.next();
				List<BaseCommonDto> dtoList = baseCategoryMapper.selectCategoryByBaseVehicleId(dto.getId());
				if (dtoList != null && dtoList.size() > 0) {
					dto.setChildrenList(dtoList);
				} else {
					it.remove();
				}
			}
		}
		return vehicleTypeList;
	}

}
